/**
 * @description 依次作为新对象的原型对象生成一个新对象
 * @param {Object} obj 作为原型的对象
 * @returns {{with: (...args: T[]) => T}} 一个包含with的对象生成函数
 * @example
 * ------------------------------
 * let obj = {a: 1}
 * mixPrototypeChain(obj).with()
 * // => obj
 * ------------------------------
 * let obj = {a: 1}
 * mixPrototypeChain(obj).with({b:2}, {c:3})
 * // => {c:3} -> __proto__ {b:2} -> __proto__ {a:1}
 */
export function mixPrototypeChain<T extends Record<string, any>>(obj: T): {with: (...args: T[]) => T} {
  return {
    with: (...mixins) => mixins.reduce((c, mix) => Object.create(c, Object.getOwnPropertyDescriptors(mix)), obj),
  }
}
